package it.getta.vicinometro.popup;

import com.google.android.maps.GeoPoint;

import it.getta.vicinometro.ActivityCallBack;
import it.getta.vicinometro.R;
import it.getta.vicinometro.utils.Utils;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

public class WhereIAmPointPopup extends VicinometroPopup {
	
	private GeoPoint mWhereIAm;

	public WhereIAmPointPopup(Context context, ActivityCallBack activityCallBack, GeoPoint whereIAm) {
		super(context, activityCallBack, R.layout.where_i_am_popup);
		mWhereIAm = whereIAm;
	}
	
	@Override
	public void showPopup() {
		super.showPopup();
		LinearLayout choose1 = (LinearLayout)mPopupRootView.findViewById(R.id.choose1);
		choose1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mActivityCallBack.showAsyncLoading();
				if(mActivityCallBack.getTrackingTask().checkForGpsEnabled()) {
					mActivityCallBack.getTrackingTask().requestLocationUpdateByGps();
				} else {
					mActivityCallBack.getTrackingTask().requestLocationUpdateByNetwork();
				}
				
				dismiss();
			}
		});
		
		LinearLayout choose2 = (LinearLayout)mPopupRootView.findViewById(R.id.choose2);
		choose2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mActivityCallBack.showListPopup(mWhereIAm);
				dismiss();
			}
		});
		showAtLocation(mActivityCallBack.getPopupAnchor(), Gravity.CENTER, 0, Utils.convertDensityPixel(-100, mContext));
		
	}
	
}
